package com.dede.screensaverhelper

import android.accessibilityservice.AccessibilityService
import android.util.Log
import android.view.KeyEvent
import android.view.accessibility.AccessibilityEvent
import com.dede.screensaverhelper.activity.DreamTempActivity

/**
 * home按键监听，无障碍服务
 * @author hsh
 * @since 2018/2/8 15:19.
 */
class HomeKeyEventServer : AccessibilityService() {

    private val TAG = "HomeKeyEventServer"

    override fun onInterrupt() {
        Log.i(TAG, "onInterrupt: ")
    }

    override fun onAccessibilityEvent(event: AccessibilityEvent?) {
        Log.i(TAG, "onAccessibilityEvent: ")
    }

    override fun onServiceConnected() {
        super.onServiceConnected()
        Log.i(TAG, "onServiceConnected: ")
    }

    override fun onKeyEvent(event: KeyEvent?): Boolean {
        Log.i(TAG, "onKeyEvent: " + event?.keyCode)
        if (DreamTempActivity.isDreaming()) {
            return true
        }
//        if (event?.keyCode == KeyEvent.KEYCODE_HOME) {
//        }
        return super.onKeyEvent(event)
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.i(TAG, "onDestroy: ")
    }
}